package org.come.Jpanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.swing.*;

import com.tool.tcpimg.RichLabel;
import io.netty.channel.ChannelHandlerContext;
import org.apache.commons.lang.StringUtils;
import org.come.Frame.AnswerMinJframe;
import org.come.Frame.GangsGuardJframe;
import org.come.Frame.NPCJfram;
import org.come.Frame.ZhuFrame;
import org.come.action.MapAction;
import org.come.action.NpcMenuAction;
import org.come.bean.*;
import org.come.control.KejuControl;
import org.come.entity.Goodstable;
import org.come.entity.RoleSummoning;
import org.come.gltools.RendererTools;
import org.come.model.Door;
import org.come.model.Npctable;
import org.come.model.Pet;
import org.come.model.Talk;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.*;

import com.tool.ModerateTask.TaskData;
import com.tool.ModerateTask.TaskMixDeal;
import com.tool.ModerateTask.TaskProgress;
import com.tool.ModerateTask.TaskRoleData;
import com.tool.ModerateTask.TaskSet;
import com.tool.PlayerKill.PKSys;
import com.tool.image.ImageMixDeal;
import com.tool.image.ManimgAttribute;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

import io.netty.util.internal.StringUtil;

 

// NPC对话框面板
public class NPCJpanel extends JPanel {
    private JTextArea testMes;// 用来显示聊天信息
    private List<Door> doors;// npc传送功能集合
    private String[] npcsStrings;// npc 功能集合
    private List<String> npcfunction = new ArrayList<>();
    private JList<String> list1;
    private int ys = 0;
    private String npctype;// npc类型
    private String pettype;// npc类型
    private MapMonsterBean mapMonsterBean;// 野怪数据
    private TaskProgress taskMonster;// 任务怪数据
    private Npctable npctable;
    private Goodstable good;
    private String[] Fvalue;
    /** 记录npc的数据 */
    private NpcInfoBean npcInfoBean;
    private Integer taskId;
    private static JLabel newTitlelab = new JLabel();
    public Integer getTaskId() {
        return taskId;
    }

    public NPCJpanel() {
        this.setPreferredSize(new Dimension(534, 208));
        this.setOpaque(false);

        testMes = new JTextArea();
        testMes.setMargin(new Insets(13, 10, 18, 10));
        testMes.setLineWrap(true);// 自动换行
        testMes.setOpaque(false);
        testMes.setFont(UIUtils.TEXT_FONT1);
        testMes.setForeground(Color.white);
        testMes.setText("");
        list1 = new JList() {
            @Override
            public int locationToIndex(Point location) {
                int index = super.locationToIndex(location);
                if (index != -1 && !getCellBounds(index, index).contains(location)) {
                    return -1;
                } else {
                    return index;
                }
            }
        };
        list1.setOpaque(false);
        list1.setBackground(UIUtils.Color_BACK);
        list1.setForeground(Color.green);
        list1.setFont(UIUtils.TEXT_FONT1);
        list1.setSelectionForeground(Color.green);
        list1.setSelectionBackground(UIUtils.Color_BACK);

        list1.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                list1.setCellRenderer(new RendererTools(list1.locationToIndex(e.getPoint()), new Color(135, 135, 135, 100)));
                MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);//对话框输出手指
            }
        });
        list1.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                FormsManagement.showForm(289);
                final JList list = (JList)e.getSource();
                if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown() && !this.isMenuShortcutKeyDown((InputEvent)e)) {
                    list.clearSelection();
                }
                FormsManagement.HideForm(27);
                if (list.getSelectedIndex() == -1) {
                    return;
                }
                else {
                    int i = 0;
                    while (i <= NPCJpanel.this.list1.getMaxSelectionIndex()) {
                        NPCJpanel.this.list1.setCellRenderer(new RendererTools(i, new Color(0, 0, 0, 0)));
                        ++i;
                    }
                    if (!"我什么都不做".equals(NPCJpanel.this.npcsStrings[list.getSelectedIndex()]) && !"没钱，给酒的行不？".equals(NPCJpanel.this.npcsStrings[list.getSelectedIndex()])) {
                        ((NpcMenuAction)MapAction.npcmenuAction.get("菜单")).menuControl(NPCJpanel.this.npcsStrings[list.getSelectedIndex()]);
                    }
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                    return;
                }
            }

            private boolean isMenuShortcutKeyDown(final InputEvent event) {
                return (event.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0x0;
            }
        });
        this.setLayout(new BorderLayout());
        this.add(testMes, BorderLayout.NORTH);
        JTextArea testMes1 = new JTextArea();
        testMes1.setBounds(10, 10, 20, 100);
        testMes1.setOpaque(false);
        testMes1.setMargin(new Insets(0, 10, 0, 0));
        this.add(testMes1, BorderLayout.WEST);
        JTextArea testMes2 = new JTextArea();
        testMes2.setBounds(10, 10, 20, 100);
        testMes2.setOpaque(false);
        testMes2.setMargin(new Insets(0, 10, 0, 0));
        this.add(testMes2, BorderLayout.EAST);
        this.add(list1, BorderLayout.CENTER);
    }

    public static ImageIcon icon;
    /** 字段名:headImg NPC头像<br> */
    private ImageIcon headImg;
    /** 字段名:headHeight 头像图片高度<br> */
    private int headHeight = 0;

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 画出背景图(npc聊天背景)
//        if (icon == null)
        		icon = new ImageIcon("inkImg/newbackground/B233.png");
        if (headImg != null) {
            g.drawImage(headImg.getImage(), 2, 1, headImg.getIconWidth(),headImg.getIconHeight(), this);
        }
        g.drawImage(icon.getImage(), 0, headHeight, 534, 208, this);
    }

    /** 打开传送器的对话界面 */
    public void FlightMsg(Goodstable good) {
        String[] vs = good.getValue().split("\\|");
        String[] path = vs[0].split("=")[1].split(",");
        String wz = path[1] + "(" + path[2] + "," + path[3] + ")";
        testMes.setText("你真的要去" + wz + "吗？");
        this.good = good;
        Fvalue = new String[] { wz };
        FormsManagement.HideForm(27);
        npcfunction.clear();
        npcfunction.add("快送我去");
        npcfunction.add("重新做路标");
        npcfunction.add("我什么都不想做");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        changeImage(null);
    }

    /** 打开多坐标传送器 */
    public void FlightMsgS(Goodstable good) {
        FormsManagement.HideForm(27);
        this.good = good;
        testMes.setText("记录多个坐标的飞行棋");
        // 传送=1209,长安杂货店,466,378|可用次数=99
        npcfunction.clear();
        String[] vs = good.getValue().split("\\|");
        for (int i = 0; i < vs.length; i++) {
            if (vs[i].startsWith("传送")) {
                vs[i] = vs[i].split("=")[1];
                String[] path = vs[i].split(",");
                npcfunction.add(path[1] + "(" + path[2] + "," + path[3] + ")");
            } else {
                vs[i] = null;
            }
        }
        Fvalue = vs;
        if (vs.length < 6) {
            npcfunction.add("新增坐标");
        }
        showList(null);
    }
    public void showPetNameList() {
        removedizi();
        FormsManagement.HideForm(27);
        npcfunction.clear();
        testMes.setText("#24#W请选择下列要重修召唤兽的终极技能，需要费用#G5亿");

        List<RoleSummoning> list = UserMessUntil.getPetListTable();
        for(RoleSummoning pet:list){
            if(StringUtils.isNotBlank(pet.getPetSkills())){
                String[] skilIds = pet.getPetSkills().split("\\|");
                for(String skillId:skilIds){
                    if(getzjSkill(skillId)){
                        Skill skill = UserMessUntil.getSkillId(skillId);
                        if(skill!=null){
                            npcfunction.add(pet.getSummoningname()+"|"+skill.getSkillname()+":"+"终极技能重修");
//                            npcfunction.add("召唤兽名称:"+pet.getSummoningname()+"|"+"拥有技能:"+skill.getSkillname()+":"+"终极技能重修");
                        }
                    }
                }
            }
        }
        showList(null);
    }
    public static boolean getzjSkill(String skill){
        if(skill.equals("1606") || skill.equals("1607") || skill.equals("1608") || skill.equals("1828") || skill.equals("1829") || skill.equals("1830") || skill.equals("1840") || skill.equals("1841") || skill.equals("1842") || skill.equals("1867") || skill.equals("1868") || skill.equals("1869")){
            return true;
        }
        return false;
    }
    public void showMap() {
    	removedizi();
        FormsManagement.HideForm(27);
        npcfunction.clear();
    	npcfunction.add("长安城(4070,2710)");
    	npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        FlightMsgSD("长安城(4070,2710)");
        FormsManagement.showForm(27);
    }
    /** 检测是否点到飞行棋的坐标 */
    public boolean FlightMsgSD(String value) {
        if (good == null || Fvalue == null) {
            return false;
        }
        for (int i = 0; i < Fvalue.length - 1; i++) {
            if (Fvalue[i] != null) {
                String[] path = Fvalue[i].split(",");
                String wz = path[1] + "(" + path[2] + "," + path[3] + ")";
                if (value.equals(wz)) {
                    Fvalue = new String[] { wz };
                    FormsManagement.HideForm(27);
                    testMes.setText("你真的要去" + value + "吗？");
                    npcfunction.clear();
                    npcfunction.add("快送我去");
                    npcfunction.add("删除路标");
                    npcfunction.add("重新做路标");
                    showList(null);
                    return true;
                }
            }
        }
        return false;
    }

    public void keju() {//科举答题顺序
        npcfunction.clear();
        testMes.setText(KejuControl.vs[1]);
        Random random = new Random();
        if (random.nextInt(4) == 0) {

            npcfunction.add(KejuControl.vs[2]);
            npcfunction.add(KejuControl.vs[3]);
            npcfunction.add(KejuControl.vs[4]);
            npcfunction.add(KejuControl.vs[5]);
        } else if (random.nextInt(4) == 1) {
            npcfunction.add(KejuControl.vs[3]);
            npcfunction.add(KejuControl.vs[4]);
            npcfunction.add(KejuControl.vs[5]);
            npcfunction.add(KejuControl.vs[2]);

        } else if (random.nextInt(4) == 2) {
            npcfunction.add(KejuControl.vs[4]);
            npcfunction.add(KejuControl.vs[5]);
            npcfunction.add(KejuControl.vs[2]);
            npcfunction.add(KejuControl.vs[3]);

        } else if (random.nextInt(4) == 3) {
            npcfunction.add(KejuControl.vs[5]);
            npcfunction.add(KejuControl.vs[4]);
            npcfunction.add(KejuControl.vs[3]);
            npcfunction.add(KejuControl.vs[2]);

        } else {
            npcfunction.add(KejuControl.vs[3]);
            npcfunction.add(KejuControl.vs[5]);
            npcfunction.add(KejuControl.vs[2]);
            npcfunction.add(KejuControl.vs[4]);
        }

        showList(npcInfoBean.getNpctable().getSkin());
        KejuControl.vs = null;
    }

    /**
     * 根据不同师傅显示技能列表
     */
    public void showskill(int npctype) {
        npcfunction.clear();
        switch (npctype) {
            case 19:
                npcfunction.add("雷霆霹雳");
                npcfunction.add("日照光华");
                npcfunction.add("雷神怒击");
                npcfunction.add("电闪雷鸣");
                npcfunction.add("天诛地灭");
                break;
            case 20:
                npcfunction.add("地狱烈火");
                npcfunction.add("天雷怒火");
                npcfunction.add("三味真火");
                npcfunction.add("烈火骄阳");
                npcfunction.add("九阴纯火");
                break;
            case 21:
                npcfunction.add("飞砂走石");
                npcfunction.add("乘风破浪");
                npcfunction.add("太乙生风");
                npcfunction.add("风雷涌动");
                npcfunction.add("袖里乾坤");
                break;
            case 22:
                npcfunction.add("龙卷雨击");
                npcfunction.add("龙腾水溅");
                npcfunction.add("龙啸九天");
                npcfunction.add("蛟龙出海");
                npcfunction.add("九龙冰封");
                break;
            case 23:
                npcfunction.add("作茧自缚");
                npcfunction.add("金蛇缠丝");
                npcfunction.add("天罗地网");
                npcfunction.add("作壁上观");
                npcfunction.add("四面楚歌");
                break;
            case 24:
                npcfunction.add("催眠咒");
                npcfunction.add("瞌睡咒");
                npcfunction.add("离魂咒");
                npcfunction.add("迷魂醉");
                npcfunction.add("百日眠");
                break;
            case 25:
                npcfunction.add("蛇蝎美人");
                npcfunction.add("追魂迷香");
                npcfunction.add("断肠烈散");
                npcfunction.add("鹤顶红粉");
                npcfunction.add("万毒攻心");
                break;
            case 26:
                npcfunction.add("反间之计");
                npcfunction.add("情真意切");
                npcfunction.add("谗言相加");
                npcfunction.add("借刀杀人");
                npcfunction.add("失心狂乱");
                break;
            case 27:
                npcfunction.add("夺命勾魂");
                npcfunction.add("追神摄魄");
                npcfunction.add("魔音摄心");
                npcfunction.add("销魂蚀骨");
                npcfunction.add("阎罗追命");
                break;
            case 28:
                npcfunction.add("妖之魔力");
                npcfunction.add("力神复苏");
                npcfunction.add("狮王之怒");
                npcfunction.add("兽王神力");
                npcfunction.add("魔神附身");
                break;
            case 29:
                npcfunction.add("红袖添香");
                npcfunction.add("莲步轻舞");
                npcfunction.add("楚楚可怜");
                npcfunction.add("魔神护体");
                npcfunction.add("含情脉脉");
                break;
            case 30:
                npcfunction.add("魔之飞步");
                npcfunction.add("急速之魔");
                npcfunction.add("魔神飞舞");
                npcfunction.add("天外飞魔");
                npcfunction.add("乾坤借速");
                break;
            case 72:
                npcfunction.add("幽冥鬼火");
                npcfunction.add("火影迷踪");
                npcfunction.add("冥烟销骨");
                npcfunction.add("落日熔金");
                npcfunction.add("血海深仇");
                break;
            case 73:
                npcfunction.add("吸血水蛭");
                npcfunction.add("六翅毒蝉");
                npcfunction.add("啮骨抽髓");
                npcfunction.add("血煞之蛊");
                npcfunction.add("吸星大法");
                break;
            case 74:
                npcfunction.add("麻沸散");
                npcfunction.add("鬼失惊");
                npcfunction.add("乱魂钉");
                npcfunction.add("失心疯");
                npcfunction.add("孟婆汤");
                break;
            case 75:
                npcfunction.add("幽怜魅影");
                npcfunction.add("醉生梦死");
                npcfunction.add("一曲销魂");
                npcfunction.add("秦丝冰雾");
                npcfunction.add("倩女幽魂");
                break;
            default:
                break;
        }
        npcfunction.add("我什么都不想做");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        FormsManagement.showForm(27);
    }

    public JTextArea getTestMes() {
        return testMes;
    }

    public void setTestMes(JTextArea testMes) {
        this.testMes = testMes;
    }

    public List<Door> getDoors() {
        return doors;
    }

    public void setDoors(List<Door> doors) {
        doors = null;
        this.doors = doors;
    }

    /**
     *
     * @time 2019年12月27日 上午11:19:33<br>
     * @param skin
     */
    public void changeImage(String skin) {
        FormsManagement.showForm(27);
        headImg = null;
        headHeight = 0;
        if (skin != null) {
            HeadImgBean npcHeadImg = CutButtonImage.getNPCHeadImg(skin);
            if (npcHeadImg!=null) {
                headImg = npcHeadImg.getHeadImg();
                headHeight = headImg.getIconHeight();
            }
        }
        testMes.setMargin(new Insets(13 + headHeight, 10, 18, 10));
//        NPC对话窗口显示位置
        NPCJfram.getNpcJfram().setBounds(ScrenceUntil.Screen_x / 2 - 267,(ScrenceUntil.Screen_y-(headHeight + 200))/3,534,headHeight + 208);

    }
    /** 弹出npc对话 */
    public void npc(NpcMenuBean npcMenu,int type) {
        removedizi();
        npctype = type+"";
        FormsManagement.HideForm(27);
        npcfunction.clear();
        if (npcMenu != null) {
            if (npcMenu.getSureBean() != null) {
                if (npcMenu.getSureBean().getConditions() != null) {// 目前只有法术有判断
                    String[] vs = npcMenu.getSureBean().getConditions().split("-");
                    for (int i = 0; i < vs.length; i++) {
                        if (vs[i].equals(ImageMixDeal.userimg.getRoleShow().getSpecies_id().toString())) {
                            Iterator<String> iter = npcMenu.getSureBean().getMenuAndMethod().keySet().iterator();
                            while (iter.hasNext()) {
                                String key = iter.next();
                                npcfunction.add(key);
                            }
                        }
                    }
                }
            }
            Iterator<String> iter = npcMenu.getInittitle().keySet().iterator();
            while (iter.hasNext()) {
                String key = iter.next();
                npcfunction.add(key);
            }
        }
        testMes.setText("");
        showList(null);
    }
    /** 弹出npc对话 */
    public void npc(NpcMenuBean npcMenu, NpcInfoBean npcInfoBean) {
        removedizi();
        npctype = npcInfoBean.getNpctable().getNpctype();
        this.npcInfoBean = npcInfoBean;
        FormsManagement.HideForm(27);
        if (npctype.equals("101")) {
            GetOut();
            return;
        }
        if (npctype.equals("102")) {
            ZiShou();
            return;
        }

        if (npctype.equals("99129")) {
            if(!npcInfoBean.getNpctable().getRoleId().equals(RoleData.getRoleData().getLoginResult().getRole_id().toString())) {
                if(npcInfoBean.getNpctable().getSkin().equals("700011") || npcInfoBean.getNpctable().getSkin().equals("700012")) {
                    if(DataUtil.isEmpty(npcInfoBean.getNpctable().getRoleIdName()) || !npcInfoBean.getNpctable().getRoleIdName().contains(RoleData.getRoleData().getLoginResult().getRole_id().toString()+RoleData.getRoleData().getLoginResult().getRolename())) {
                        FormsManagement.showForm(3075);
                        AnswerMinJframe.getAnswerMinJpanel().getWt();
                        AnswerMinJframe.getAnswerMinJpanel().NPCID = npcInfoBean.getNpctable().getNpcid();
                        AnswerMinJframe.getAnswerMinJpanel().initTimer();
                    }else {
                        newTitlelab.setText("");
                        npcfunction.clear();
                        testMes.setText("小树苗已经长成了参天大树，此树苗用观音姐姐的水滋养，镇元大仙亲自施肥，用太上老君的仙丹做养料，吸收天地精华，日月灵气，历经千载，方才长成！可带来无尽财富和福运！");
                        npcfunction.add("我什么也不做");
                        showList(null);
                    }
                    return;
                }else {
                    newTitlelab.setText("");
                    npcfunction.clear();
                    testMes.setText("这不是您钟的树哦，您也可以种招财进宝树，长安桥每日必做领取小树苗！");
                    showList(null);
                    return;
                }
            }else {
                if(Integer.parseInt(npcInfoBean.getNpctable().getNum())<3) {
                    newTitlelab.setText("");
                    npcfunction.clear();
                    testMes.setText("您已照顾您的小树苗"+npcInfoBean.getNpctable().getNum()+"次了");
                    npcfunction.add("我要浇水");
                    npcfunction.add("我要除虫");
                    npcfunction.add("我要施肥");
                    npcfunction.add("我什么也不做");
                    showList(null);
                    return;
                }else {
                    if(npcInfoBean.getNpctable().getSkin().equals("700011") || npcInfoBean.getNpctable().getSkin().equals("700012")) {
                        if(DataUtil.isEmpty(npcInfoBean.getNpctable().getRoleIdName()) || !npcInfoBean.getNpctable().getRoleIdName().contains(RoleData.getRoleData().getLoginResult().getRole_id().toString()+RoleData.getRoleData().getLoginResult().getRolename())) {
                            FormsManagement.showForm(3075);
                            AnswerMinJframe.getAnswerMinJpanel().getWt();
                            AnswerMinJframe.getAnswerMinJpanel().NPCID = npcInfoBean.getNpctable().getNpcid();
                            AnswerMinJframe.getAnswerMinJpanel().initTimer();
                        }else {
                            newTitlelab.setText("");
                            npcfunction.clear();
                            testMes.setText("您的小树苗已经长成了参天大树，此树苗用观音姐姐的水滋养，镇元大仙亲自施肥，用太上老君的仙丹做养料，吸收天地精华，日月灵气，历经千载，方才长成！可带来无尽财富和福运！");
                            npcfunction.add("我什么也不做");
                            showList(null);
                        }
                        return;
                    }else {
                        newTitlelab.setText("");
                        npcfunction.clear();
                        testMes.setText("您的小树苗已经长成了参天大树！");
                        npcfunction.add("我什么也不做");
                        showList(null);
                        return;
                    }
                }
            }
        }

        if (npctype.equals("889")) {
            if (KejuControl.vs == null || KejuControl.vs.length == 0 || KejuControl.vs[0] == null || KejuControl.vs[0].isEmpty()) {
                testMes.setText("御前科举考试还没开始，请稍后再试");
                if (npcInfoBean != null && npcInfoBean.getNpctable() != null) {
                    showList(npcInfoBean.getNpctable().getSkin());
                }
                return;
            }
            try {
                int kejuStatus = Integer.parseInt(KejuControl.vs[0]);
                if (kejuStatus == 9999) {
                    testMes.setText("御前科举还未开始，请耐心等待");
                    if (npcInfoBean != null && npcInfoBean.getNpctable() != null) {
                        showList(npcInfoBean.getNpctable().getSkin());
                    }
                    return;
                } else {
//                    keju();
                    return;
                }
            } catch (NumberFormatException e) {
                testMes.setText("御前科举状态异常，请联系管理员");
                if (npcInfoBean != null && npcInfoBean.getNpctable() != null) {
                    showList(npcInfoBean.getNpctable().getSkin());
                }
                return;
            }
        }
        npcfunction.clear();
        if (npcMenu != null) {
            if (npcMenu.getSureBean() != null) {
                if (npcMenu.getSureBean().getConditions() != null) {
                    // 目前只有法术有判断
                    String[] vs = npcMenu.getSureBean().getConditions()
                            .split("-");
                    for (int i = 0; i < vs.length; i++) {
                        if (vs[i].equals(ImageMixDeal.userimg.getRoleShow()
                                .getSpecies_id().toString())) {
                            Iterator<String> iter = npcMenu.getSureBean()
                                    .getMenuAndMethod().keySet().iterator();
                            while (iter.hasNext()) {
                                String key = iter.next();
                                npcfunction.add(key);
                            }
                        }
                    }
                }
            }
            Iterator<String> iter = npcMenu.getInittitle().keySet().iterator();
            while (iter.hasNext()) {
                String key = iter.next();
                npcfunction.add(key);
            }
        }
        if (npcInfoBean.getDoors() != null) {
            for (int i = 0; i < npcInfoBean.getDoors().size(); i++) {
                if (npcInfoBean.getDoors().get(i) != null
                        && npcInfoBean.getDoors().get(i).getDoorkey() != null) {
                    npcfunction.add(npcInfoBean.getDoors().get(i).getDoorkey());
                }
            }
        }

        String npcway = npcInfoBean.getNpctable().getNpcway();
        if (!"2".equals(npctype) && npcway != null && !"".equals(npcway)) {
            String[] v = npcway.split(" ");
            for (int i = 0; i < v.length; i++) {
                List<String> tasks = SplitStringTool.splitString(v[i]);
                String task = TaskMixDeal.taskoption(tasks.get(0));
                if (task != null) {
                    npcfunction.add(task);
                }
            }
        }
        TaskProgress taskdata=TaskMixDeal.KillNpc(Integer.parseInt(npcInfoBean.getNpctable().getNpcid()));
        TaskData data=taskdata!=null?taskdata.getTask().getTaskData():null;
        if (data!=null) {
            npcfunction.add("我是来击杀你的");
            for (int i = 1; i <=data.getNd(); i++) {
                if (i==1) {npcfunction.add("我是来击杀你的(困难难度)");}
                else if (i==2) {npcfunction.add("我是来击杀你的(卓越难度)");}
                else if (i==3) {npcfunction.add("我是来击杀你的(地狱难度)");}
                else if (i==4) {npcfunction.add("我是来击杀你的(天堂难度)");}
            }
        }
//		for (int i = 0; i < npcfunction.size(); i++) {
//			if (npcfunction.get(i).equals("我什么都不做")) {
//				npcfunction.remove(i);
//				npcfunction.add("我什么都不做");
//				break;
//			}
//		}
        if (npcInfoBean.getTalks() != null && npcInfoBean.getTalks().size() != 0) {
            Talk talk = npcInfoBean.getTalks().get(Util.random.nextInt(npcInfoBean.getTalks().size()));
            if (talk != null) {
                testMes.setText(talk.getTalktext() +  ("801".equals(npctype) ? "   （本日已完成 " + TaskRoleData.SumReceive(801, 2) + "/"+UserMessUntil.getTaskSet(Integer.parseInt(npctype)).getSumlimit()+"）" : ""));
                // 判断元旦孵蛋任务，添加孵化值
                if ("400102".equals(npcInfoBean.getNpctable().getNpcid())) {
                    // 向服务器要孵化值
                    SendMessageUntil.toServer(Agreement.getAgreement().HatchvalueAgreement(""));
                }
            } else {
                testMes.setText("");
            }
        } else {
            testMes.setText("");
        }
        showList(npcInfoBean.getNpctable().getSkin());
    }

    // 弹出npc对话
    public void npc(NPCDialog npcDialog) {
        removedizi();

        testMes.setLineWrap(true);
        testMes.setText(npcDialog.getMsg());
        if (npcDialog.getType() != null) {
            if (npcDialog.getType().startsWith("N")) {
                npctype = npcDialog.getType().substring(1);
            } else if (npcDialog.getType().startsWith("M")) {
                int I = Integer.parseInt(npcDialog.getType().substring(1));
                List<ManimgAttribute> mapMonsterlist = ImageMixDeal.mapMonsterlist;
                if (mapMonsterlist == null) {
                    return;
                }
                for (int i = mapMonsterlist.size() - 1; i >= 0; i--) {
                    MapMonsterBean bean = mapMonsterlist.get(i)
                            .getMapMonsterBean();
                    if (bean.getI() == I) {
                        mapMonsterBean = bean;
                        break;
                    }
                }
                if (mapMonsterBean == null) {
                    return;
                }
            }
        }
        if (npcDialog.getFunctions() != null) {
            npcsStrings = new String[npcDialog.getFunctions().size()];
            for (int i = 0; i < npcsStrings.length; i++) {
                npcsStrings[i] = npcDialog.getFunctions().get(i);
            }
            list1.setListData(npcsStrings);
        } else {
            npcsStrings = new String[1];
            npcsStrings[0] = "我什么都不做";
            list1.setListData(npcsStrings);
        }

        if (npctype != null && StringUtil.isNullOrEmpty(npcDialog.getMsg())) {
            for(ManimgAttribute attr : ImageMixDeal.npcimglist) {
                if(attr.getNpc().getNpctable().getNpctype().equals(npctype)) {
                    if (attr.getNpc().getTalks() != null && attr.getNpc().getTalks().size() != 0) {
                        Talk talk = attr.getNpc().getTalks().get(Util.random.nextInt(attr.getNpc().getTalks().size()));
                        if (talk != null) {
                            testMes.setText(talk.getTalktext());
                        }
                    }
                    changeImage(attr.getNpc().getNpctable().getSkin());
                    return;
                }
            }
        }
        changeImage(null);
    }

    /**
     * 清空静态地址
     */
    public void removedizi() {
        mapMonsterBean = null;// 野怪数据
        taskMonster = null;// 任务怪数据
        npcInfoBean = null;
        good = null;
        Fvalue = null;
        pettype = null;
        npctype = null;
    }

    /** 任务结束弹出对话 */
    public void taskend(String text) {
        removedizi();
        FormsManagement.HideForm(27);
        if (text == null || "".equals(text)) {
            return;
        }
        npcsStrings = new String[0];
        list1.setListData(npcsStrings);
        testMes.setText(text);
        changeImage(null);
    }

    /**
     * 点击野怪弹出的对话框（未领取任务）
     *
     * @return
     */
    public void yeguai2(MapMonsterBean monsterBean) {
        removedizi();
        mapMonsterBean = monsterBean;
        FormsManagement.HideForm(27);
        npcfunction.clear();
        npcsStrings = new String[] {"你等着，我这就去领"};
        list1.setListData(npcsStrings);
        testMes.setText("任务都没领也想来挑战我？");
        changeImage(monsterBean.getRobotskin());
    }

    /**
     * 点击野怪弹出的对话框
     *
     * @return
     */
    public void yeguai(MapMonsterBean monsterBean) {
        removedizi();
        mapMonsterBean = monsterBean;
        FormsManagement.HideForm(27);

        npcfunction.clear();
        int robotType = monsterBean.getRobottype();
        if (robotType == 2) {
            npcfunction.add("我想买点东西");
        } else if ((robotType == 4 || robotType == 132)
                && monsterBean.getFollow() != null) {
            npcfunction.add("我是来劫道的");
        } else {
            npcfunction.add("满地宝物先抢一个在说");
        }
        npcfunction.add("我什么都不想做");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        testMes.setText("想要我身上的宝物吗? 想要就来抢啊!");
        changeImage(monsterBean.getRobotskin());
    }

    /** 点击任务怪弹出的对话框 */
    public void task(TaskProgress taskdata) {
        FormsManagement.HideForm(27);
        removedizi();

        taskMonster=taskdata;
        npcfunction.clear();

        npcfunction.add("我是来击杀你的");
        TaskData data=taskdata.getTask().getTaskData();
        if (data!=null) {
            for (int i = 1; i <=data.getNd(); i++) {
                if (i==1) {npcfunction.add("我是来击杀你的(困难难度)");}
                else if (i==2) {npcfunction.add("我是来击杀你的(卓越难度)");}
                else if (i==3) {npcfunction.add("我是来击杀你的(地狱难度)");}
                else if (i==4) {npcfunction.add("我是来击杀你的(天堂难度)");}
            }
        }
        npcfunction.add("我什么都不想做");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        testMes.setText("这里风景还不差");
        changeImage(null);
    }

    /** 召唤兽第二次飞升选择是否改变皮肤弹出的对话框 */
    public void whetherChange(BigDecimal petId) {
        removedizi();
        pettype = petId.toString();
        FormsManagement.HideForm(27);
        npcfunction.clear();
        npcfunction.add("是");
        npcfunction.add("否");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        testMes.setText("是否变化该召唤兽的造型");
        changeImage(null);
    }

    /** 召唤兽第三次飞升弹出的对话框 */
    public void selectValue(BigDecimal petId, int value) {
        removedizi();
        pettype = petId + "|" + value;
        FormsManagement.HideForm(27);
        npcfunction.clear();
        npcfunction.add("HP");
        npcfunction.add("MP");
        npcfunction.add("AP");
        npcfunction.add("SP");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        testMes.setText("请选择下面其中一项增加" + value + "点的基础值");
        changeImage(null);
    }


    /** 强制离婚 */
    public void compulsoryDivorce() {
        FormsManagement.HideForm(27);
        npcfunction.clear();
        npcfunction.add("确定");
        npcfunction.add("我再考虑考虑");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        testMes.setText("您的对象没有一起过来，您确定要单方面强制离婚（离婚费用：5000W两）。 ");
        changeImage(null);
    }

    /** 选择打开吉祥如意蛋的方式 */
    public void openJxryd() {
        FormsManagement.HideForm(27);
        npcfunction.clear();
        npcfunction.add("直接打开");
        npcfunction.add("祈福（500W金币）");
        npcsStrings = new String[npcfunction.size()];
        for (int i = 0; i < npcsStrings.length; i++) {
            npcsStrings[i] = npcfunction.get(i);
        }
        list1.setListData(npcsStrings);
        testMes.setText("选择打开吉祥如意蛋的方式（祈福奖励更丰富）");
        changeImage(null);
    }

    /**处理不同出狱的npc弹窗*/
    public void GetOut() {
        PKSys pkSys = PKSys.getPkSys();
        if (pkSys.getPk2() == 0) {
            testMes.setText("一个良民瞎点啥,在闹请你进去");
            npcsStrings = new String[] {"我要回长安"};
        } else {
            if (pkSys.getPk1() != 0) {
                StringBuffer buffer = new StringBuffer();
                buffer.append(ImageMixDeal.userimg.getRoleShow().getRolename());
                buffer.append(",你还有");
                buffer.append(pkSys.getPk1());
                buffer.append("点PK标志未清除");
                testMes.setText(buffer.toString());
                npcsStrings = new String[] { "我什么都不做" };
            } else if (pkSys.getPk2() == 1) {
                testMes.setText("今天又收到红色炸弹了。哎日子难过啊");
                npcsStrings = new String[] {"这是8888W,小小意识","别愁,我去帮你筹点钱","哦?大爷是来办理出狱手续" };
            } else {
                testMes.setText("今天天气真好,是出狱的好日子");
                npcsStrings = new String[] { "我是来办理出狱手续" };
            }
        }
        list1.setListData(npcsStrings);
        changeImage(null);
    }

    // 自首
    public void ZiShou() {
        PKSys pkSys = PKSys.getPkSys();
        if (pkSys.getPk1() == 0) {
            testMes.setText("一个良民瞎点啥,在闹请你进去");
            npcsStrings = new String[] {"我想去死牢探监","我想去地牢探监","我想去天牢探监"};
        } else {
            StringBuffer buffer = new StringBuffer();
            buffer.append(ImageMixDeal.userimg.getRoleShow().getRolename());
            buffer.append(",你还有");
            buffer.append(pkSys.getPk1());
            buffer.append("点PK标志自首可以减轻罪行");
            testMes.setText(buffer.toString());
            npcsStrings = new String[] { "我是来自首的", "我什么都不做" };
        }
        list1.setListData(npcsStrings);
        changeImage(null);
    }
    public void bshctanchuang() {
        npcfunction.clear();
        testMes.setText("宝石合成，打造，拆解。");
        npcfunction.add("我要打造,摘抄宝石");
        npcfunction.add("我要合成宝石等");
        npcfunction.add("我想买点东西");
        showList(null);
    }
    public void pspytanchuang() {
        npcfunction.clear();
        testMes.setText("配饰培养重铸，护身符彩晶石培养 神饰解封");
        npcfunction.add("我要培养护身符");
        npcfunction.add("我要重铸护身符");
        npcfunction.add("我要培养饰品");
        npcfunction.add("我要重铸饰品");
        npcfunction.add("培养彩晶石");
        npcfunction.add("我要解封神饰");
        npcfunction.add("我什么都不做");
        showList(null);
    }

    public void huangMsg() {
        npcfunction.clear();
        testMes.setText("头彩（两骰顺序相同）赔率：1赢25\n" +
                "可以先查询当前头彩号码，若选择购买头彩的话，要出的骰子号码及顺序与头彩均相同的话，则表示买中。\n" +
                "例如：头彩是2+6，若开出的骰子也为2+6则中，但6+2就不中。\n" +
                "七星（两骰之和为7）赔率：1赔5。\n" +
                "对对（两骰号相同且为偶数）赔率：1赔10.\n" +
                "散星（两骰之和为三，五，九，十一）赔率：1赔2\n" +
                "除早7-8点外全天开启，每五分钟开奖一次。");
        showList(null);
    }
    public void xqhctanchuang() {
        npcfunction.clear();
        testMes.setText("仙器合成,升级，洗练，重铸，改变模型");
        npcfunction.add("我要合成仙器");
        npcfunction.add("我要升级仙器");
        npcfunction.add("我要洗炼仙器");
        npcfunction.add("我要重铸仙器");
        npcfunction.add("改变仙器模型");
        npcfunction.add("我什么都不做");
        showList(null);
    }
    public void sbdztanchuang() {
        npcfunction.clear();
        testMes.setText("打造11级或者以上高级装备");
        npcfunction.add("打造11级以上高级装备");
        npcfunction.add("我什么都不做");
        showList(null);
    }
    public void zhshuanfu() {
        String pet = UserMessUntil.getChosePetMes().getSummoningname();
        npcfunction.clear();
        testMes.setText("你当前的召唤: " + "【" + pet + "】" + " 选择下面的操作方式");
        npcfunction.add("确定购买幻肤吗?");
        npcfunction.add("我什么也不做");
        showList(null);
    }
    public void sbsjtanchuang() {
        npcfunction.clear();
        testMes.setText("神兵升级,炼妖石合成，符石合成重铸 ");
        npcfunction.add("我要打造普通装备");
        npcfunction.add("我要升级神兵");
        npcfunction.add("精炼神兵");
        npcfunction.add("我要上神兵石");
        npcfunction.add("我要合成炼妖石");
        npcfunction.add("符石合成重铸");
        showList(null);
    }
    /** 显示召唤兽饰品列表 */
    public void showCJS(Goodstable goodstable) {
        good = goodstable;
        testMes.setText("将彩晶石装换为对应的召唤兽饰品");
        npcfunction.clear();
        npcfunction.add("龙马饰品");
        npcfunction.add("白龙帝饰品");
        npcfunction.add("瀚威猫将的大刀");
        npcfunction.add("棕小仙饰品");
        npcfunction.add("罗刹鬼姬饰品");
        npcfunction.add("冥雷饰品");
        npcfunction.add("西域响马饰品");
        npcfunction.add("金不换饰品");
        npcfunction.add("松鼠饰品");
        npcfunction.add("拨浪鼓饰品");
        npcfunction.add("哥俩好饰品");
        npcfunction.add("孔雀明王饰品");
        npcfunction.add("赭炎饰品");
        npcfunction.add("画皮娘子饰品");
        npcfunction.add("冥灵妃子饰品");
        npcfunction.add("黄金兽饰品");
        npcfunction.add("剑精灵饰品");
        npcfunction.add("泥石怪饰品");
        npcfunction.add("冰雪魔饰品");
        npcfunction.add("蝴蝶仙子饰品");
        npcfunction.add("凤凰饰品");
        npcfunction.add("冲冲虫饰品");
        npcfunction.add("猪怪饰品");
        npcfunction.add("符咒女娲饰品");
        npcfunction.add("精卫饰品");
        npcfunction.add("猴精饰品");
        npcfunction.add("天龙女饰品");
        npcfunction.add("吉祥果饰品");
        npcfunction.add("狮虎兽饰品");
        npcfunction.add("妙音鸾女饰品");
        npcfunction.add("碧水精魄饰品");
        npcfunction.add("俏娘子饰品");
        npcfunction.add("木甲人饰品");
        showList(null);
    }
    /** 展示星卡补充信息 */
    public void showStarCardSupplement(Goodstable goodstable) {
        String warPower = goodstable.getValue().split("\\|")[2].split("=")[1];
        npcfunction.clear();
        testMes.setText("该星卡当前战力为:" + warPower + ",可以选择以下两种补充战力");
        npcfunction.add("星芒恢复(100点=1000点战力)");
        npcfunction.add("金币恢复(1000万=1000点战力)");
        showList(null);
    }
  /**弹窗按钮*/
    public void anniutanchuang() {
        if (UserMessUntil.getChosePetMes()==null){
            ZhuFrame.getZhuJpanel().addPrompt2("没有设置参战召唤兽！");
            return;
        }
        String pet = UserMessUntil.getChosePetMes().getSummoningname();
        npcfunction.clear();
        testMes.setText("你当当前的召唤: " + "【"+pet+"】" +" 选择下面的操作方式");
        npcfunction.add("转生当前召唤兽");
        npcfunction.add("点化当前召唤兽");
//        npcfunction.add("我要启灵当前参战召唤兽");
        npcfunction.add("神兽学习技能");
        npcfunction.add("点化当前坐骑");
        npcfunction.add("飞升当前参战神兽");
        npcfunction.add("我什么也不做");
        showList(null);
    }

    public void shuangbeijingyan() {
        npcfunction.clear();
        String name = RoleData.getRoleData().getLoginResult().getRolename();
        testMes.setText("亲爱的玩家: " + "【"+    name     +  "】" +" 选择下面的操作方式");
        npcfunction.add("我要领取一小时双倍时间");
        npcfunction.add("我要领取二小时双倍时间");
        npcfunction.add ("我要领取三小时双倍时间");
        npcfunction.add ("我要冻结双倍时间");
        npcfunction.add ("我要查询剩余双倍时间");// 双倍
        npcfunction.add("我什么也不做");
        showList(null);
    }

    public  void  dangpu() {
        npcfunction.clear();
        testMes.setText("你有多少东西，我这里都可以放的下。");
        npcfunction.add("一号当铺");
        npcfunction.add("二号当铺");
        npcfunction.add("三号当铺");
        npcfunction.add("我什么也不做");
        showList(null);
    }

    public  void  wupinduihuan() {
        String name = RoleData.getRoleData().getLoginResult().getRolename();
        testMes.setText("亲爱的玩家: " + "【"+name+"】" +" 选择下面的操作方式");
        npcfunction.clear();
        npcfunction.add("兑换超级龙之骨");
        npcfunction.add("兑换高级聚魄丹");
        npcfunction.add("尽请期待");
        npcfunction.add("我什么也不做");
        showList(null);
    }

    public  void  yiyuan() {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        testMes.setText("亲爱的玩家" + "你当前的血量上限:"+"【"+loginResult.getHp()+"】" +" 选择下面的操作方式");
        npcfunction.clear();
        npcfunction.add("我要住店(扣除2000银两)");
        npcfunction.add("全部医治和修复");
        npcfunction.add("我什么也不做");
        showList(null);
    }

    /** 显示对话列表 */
    public void showList(String skin) {
        ys = 0;
        if (npcfunction.size() <= 7) {
            npcsStrings = new String[npcfunction.size()];
            for (int i = 0; i < npcfunction.size(); i++) {
                npcsStrings[i] = npcfunction.get(i);
            }
            list1.setListData(npcsStrings);
            changeImage(skin);
        } else {
            changeImage(skin);
            FY(0);
        }
    }

    /** 上一页 -1|下一页 1 */
    public void FY(int value) {
        ys += value;
        int max = (npcfunction.size() - 1) / 5;
        if (ys > max) {
            ys = max;
        } else if (ys < 0) {
            ys = 0;
        }
        int Smin = ys * 5;
        int Smax = (ys + 1) * 5;
        if (Smax > npcfunction.size()) {
            Smax = npcfunction.size();
        }
        int size = Smax - Smin;
        size++;
        if (ys != 0 && ys != max) {
            size++;
        }
        npcsStrings = new String[size];
        if (ys != 0) {
            npcsStrings[0] = "上一页";
        }
        for (int i = Smin; i < Smax; i++) {
            int p = i % 5;
            if (ys != 0) {
                p++;
            }
            npcsStrings[p] = npcfunction.get(i);
        }
        if (ys != max) {
            npcsStrings[npcsStrings.length - 1] = "下一页";
        }
        list1.setListData(npcsStrings);
        changeImage(null);
    }

    public String[] getNpcsStrings() {
        return npcsStrings;
    }

    public void setNpcsStrings(String[] npcsStrings) {
        this.npcsStrings = npcsStrings;
    }

    public List<String> getNpcfunction() {
        return npcfunction;
    }

    public void setNpcfunction(List<String> npcfunction) {
        this.npcfunction = npcfunction;
    }

    public JList<String> getList1() {
        return list1;
    }

    public void setList1(JList<String> list1) {
        this.list1 = list1;
    }

    public int getYs() {
        return ys;
    }

    public void setYs(int ys) {
        this.ys = ys;
    }

    public String getNpctype() {
        return npctype;
    }

    public void setNpctype(String npctype) {
        this.npctype = npctype;
    }

    public String getPettype() {
        return pettype;
    }

    public void setPettype(String pettype) {
        this.pettype = pettype;
    }

    public MapMonsterBean getMapMonsterBean() {
        return mapMonsterBean;
    }

    public void setMapMonsterBean(MapMonsterBean mapMonsterBean) {
        this.mapMonsterBean = mapMonsterBean;
    }

    public TaskProgress getTaskMonster() {
        return taskMonster;
    }

    public void setTaskMonster(TaskProgress taskMonster) {
        this.taskMonster = taskMonster;
    }

    public Npctable getNpctable() {
        return npctable;
    }

    public void setNpctable(Npctable npctable) {
        this.npctable = npctable;
    }

    public Goodstable getGood() {
        return good;
    }

    public void setGood(Goodstable good) {
        this.good = good;
    }

    public String[] getFvalue() {
        return Fvalue;
    }

    public void setFvalue(String[] fvalue) {
        Fvalue = fvalue;
    }

    public NpcInfoBean getNpcInfoBean() {
        return npcInfoBean;
    }

    public void setNpcInfoBean(NpcInfoBean npcInfoBean) {
        this.npcInfoBean = npcInfoBean;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        NPCJpanel.icon = icon;
    }

    public void baoshi() {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        testMes.setText("需要合成宝石么");
        npcfunction.clear();
        npcfunction.add("我要打造,摘抄宝石");
        npcfunction.add("我要合成宝石等");
        npcfunction.add("我想买点东西");
        showList(null);
    }
}
